﻿using System;
using System.Web.Mvc;
using IterationLife.ContentResources.Enums;
using IterationLife.ContentResources.Queries;
using IterationLife.Extensions.ControllerBase;
using IterationLife.PlatformBackEnd.AppServices.Contracts.ContentResources;
using IterationLife.PlatformBackEnd.AppServices.Dtos.ContentResources;
using Util;

namespace IterationLife.PlatformBackEnd.WebSite.Areas.ContentResources.Controllers {
    /// <summary>
    /// 内容资源评论控制器
    /// </summary>
    public class CommentController : TreeGridControllerBase<ContentResourceCommentDto, ContentResourceCommentQuery> {
        /// <summary>
        /// 初始化内容资源评论控制器
        /// </summary>
        /// <param name="service">内容资源评论服务</param>
        /// <param name="contentResourceService">内容资源服务</param>
        public CommentController( IContentResourceCommentService service,IContentResourceService contentResourceService ) 
            : base( service ) {
            ContentResourceCommentService = service;
            ContentResourceService = contentResourceService;
        }

        /// <summary>
        /// 内容资源评论服务
        /// </summary>
        protected IContentResourceCommentService ContentResourceCommentService { get; private set; }

        /// <summary>
        /// 内容资源服务
        /// </summary>
        protected IContentResourceService ContentResourceService { get; set; }

        /// <summary>
        /// 列表
        /// </summary>
        public ActionResult Grid(Guid? contentResourceId)
        {
            if (contentResourceId.IsEmpty())
                return null;
            var newsDto = ContentResourceService.GetById(contentResourceId);
            if (newsDto.State == ContentResourceState.Draft)
                return null;
            return PartialView("Index", new ContentResourceCommentDto
            {
                ContentResourceId = contentResourceId,
                ContentResourceTitle = newsDto.Title
            });
        }

    }
}